using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for Class1
/// </summary>
public class biFactory
{
    /*
    private static Usuario _instacia = null;
    private static Profesor _Profe = null;
    private static SchoolsBI.Materia _mater = null;
    private static int _IdMateria = 0;
    public static string MateriaDes = "";
    public static int IdCurso = 0;
    public static string CursoDes = "";
    public static Periodos _Per = null;
    */

    
    private static string OMateria = "OMateria";
    private static string OPeriodo = "Per";
    private static string OProfe = "Profe";
    private static string oUsuario = "Usuario";
    private static string DescripCurso = "DesCurso";
    private static string sIdCurso = "IdCurso";
    private static string sIdPeriodo = "IdPeriodo ";
    private static int _anioActual = 2008;

    public static int IdMateria
    {
        get {
            try
            {
                return ((SchoolsBI.Materia)HttpContext.Current.Session[OMateria]).IdMateria;
            }
            catch (Exception ex) {
                return 0;
            }
        }
        set
        {
            HttpContext.Current.Session[OMateria] = SchoolsBI.Materia.Buscar("IdMateria=" + value);
        }
    }

    public static int IdSede
    {
        get
        {
            try
            {
                return ((int)HttpContext.Current.Session[sIdPeriodo]);
            }
            catch (Exception ex)
            {
                return 0;
            }
        }
        set
        {
            HttpContext.Current.Session[sIdPeriodo] = value;
        }
    }

    public static Usuario User()
    {
        if (HttpContext.Current.Session[oUsuario]== null)
        {
            HttpContext.Current.Session[oUsuario] = new Usuario();
        }
        return (Usuario)HttpContext.Current.Session[oUsuario];
    }

    public static Profesor Profesor()
    {
        if (HttpContext.Current.Session[OProfe] == null)
        {
            HttpContext.Current.Session[OProfe] = new Profesor();
        }
        return (Profesor)HttpContext.Current.Session[OProfe];
    }

    public static Periodos Per
    {
        get
        {
            if (HttpContext.Current.Session[OPeriodo] == null)
            {
                Periodos _per  = new Periodos();
                _per.Anio=_anioActual;
                HttpContext.Current.Session[OPeriodo] = _per;
            }
            return (Periodos)HttpContext.Current.Session[OPeriodo];
        }
        set { HttpContext.Current.Session[OPeriodo] = value; }
    }

    public static string CursoDes {
        set { HttpContext.Current.Session[DescripCurso] = value; }
        get { return (string)HttpContext.Current.Session[DescripCurso]; }
    }

    public static int IdCurso
    {
        set { HttpContext.Current.Session[sIdCurso] = value; }
        get {
            try
            {
                return (int)HttpContext.Current.Session[sIdCurso];
            }
            catch (Exception Ex) { return 0; }
        }
    }


    public static void Profesor(Profesor profesor)
    {
        HttpContext.Current.Session[OProfe] = profesor;
    }

    public static SchoolsBI.Materia Materia()
    {
        if (HttpContext.Current.Session[OMateria] == null)
        {
            HttpContext.Current.Session[OMateria] = new SchoolsBI.Materia();
        }
        return (SchoolsBI.Materia)HttpContext.Current.Session[OMateria];
    }

    public static Periodos GetIdPeriodo(string anio, string idSede, string NroPeriodo, string OrdenPeriodo)
    {
         HttpContext.Current.Session[OPeriodo] = Periodos.Buscar("anio ='" + anio + "' and idSede = '" + idSede + "' and NroPeriodo = " + NroPeriodo + " and OrdenPeriodo = " + OrdenPeriodo + " and idTipoPlanilla = " + Materia().idTipoPlanilla);
         return (Periodos)HttpContext.Current.Session[OPeriodo];
    }

    public static string PlanillaXSL(tipoPlanilla eTipoPLanilla)
    {
        SchoolsBI.TipoPlanilla tp = biFactory.Materia().oPlanilla();

        if (tp == null)
        {
            return "";
        }

        switch (eTipoPLanilla)
        {
                
            case tipoPlanilla.Resumen:
                if (biFactory.Materia().IdIdioma == 1)
                {
                    return tp.FileXsl;
                }
                else
                {
                    return tp.FileXslIdioma;
                }
            case tipoPlanilla.Masiva:
                if (biFactory.Materia().IdIdioma == 1)
                {
                    return tp.FileDetalleCarga;
                }
                else
                {
                    return tp.FileDetalleCargaIdioma;
                };

            case tipoPlanilla.Individual:
                return "";




        }
        return "";

    }

    public static void registra(string accion, string detalle)
    {
        if (biFactory.User() != null)
        {
            Gos.Events.Events.Registrer(accion, detalle, biFactory.User().Nombre);
        }
        else
        {
            Gos.Events.Events.Registrer(accion, detalle,"");
        }
    }
}

public enum tipoPlanilla { Resumen, Masiva, Individual, Cuatrimestral}